﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BBPA.Admin.Supplier.Orders_Goods.Delivery
{
    public partial class List_waitCheck : ListPage
    {
        BLL.V_Goods bllList = new BLL.V_Goods();
        BLL.Goods bll = new BLL.Goods();
        //
        BLL.Orders_Goods bllOrders_Goods = new BLL.Orders_Goods();
        //string sql_orders_goods = "HasBuy=0 and WaitSupplierCheckNum>0 and HasCheck=0 and OrdersID in(select id from V_Orders where (State=" + (int)EnumHelper.OrdersState.GetMoney + " or State=" + (int)EnumHelper.OrdersState.Buying + " ) and FirstExpectBuyDate is not null and datediff(day,FirstExpectBuyDate,getdate())>=0 )";
        string sql_orders_goods = "HasBuy=0 and WaitSupplierCheckNum>0 and HasCheck=0 and OrdersID in(select id from V_Orders where (State=" + (int)EnumHelper.OrdersState.GetMoney + " or State=" + (int)EnumHelper.OrdersState.Buying + " )  )";
        protected void Page_Load(object sender, EventArgs e)
        {
            Master.show_btn_add = Master.show_btn_bat_del = Master.show_edit = Master.show_info = false;

            Master.BasicSQL =  "id in (select GoodsID from Orders_Goods where " + sql_orders_goods + ")";
            if (Security.GetCurrentUserType() == EnumHelper.UserType.Supplier) 
                Master.BasicSQL += " and SupplierID=" + Security.GetCurrentSupplierID();
        }
        
        public override DataSet get_Page_DataSet(string sql_, string orderby_, int pageFrom_, int pageTo_) { return bllList.GetListByPage(sql_, orderby_, pageFrom_, pageTo_); }

        //protected int CountWillSell(object goodsID_)
        //{
        //    return bllOrders_Goods.GetRecordCount("GoodsID=" + goodsID_ + " and OrdersID in (select id from Orders where State<=" + (int)EnumHelper.OrdersState.BuyFinish + ")");
        //}
        public override void bat_Page_List(string inStr_, string action_)
        {
            if (action_ == "hascheck")
            {
                foreach (string id in inStr_.Split(','))
                {
                    int thisID = DataTypePlus.requestInt(id);
                    foreach (Model.Orders_Goods modelOrders_Goods in bllOrders_Goods.GetModelList(sql_orders_goods+" and GoodsID=" + id))
                    {
                        modelOrders_Goods.HasCheck = true;
                        bllOrders_Goods.Update(modelOrders_Goods);
                    }
                }
            }
        }
        /// <summary>
        /// 获取本商品，还有多少等待点
        /// </summary>
        /// <param name="GoodsID_"></param>
        /// <returns></returns>
        protected int Goods_ExpectAmount(object GoodsID_)
        {
            int _GoodsID = DataTypePlus.requestInt(GoodsID_);
            int returnVal = 0;
            foreach (Model.Orders_Goods modelOrders_Goods in bllOrders_Goods.GetModelList(sql_orders_goods + " and GoodsID=" + _GoodsID))
            {
                returnVal += modelOrders_Goods.WaitSupplierCheckNum;
            }
            return returnVal;
        }
    }
}